﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using BISPOS.Repository;
namespace BISPOS
{
    public partial class AddPriceForm : DevExpress.XtraEditors.XtraForm
    {
        ProductRepository repository = new ProductRepository();
        Product product = new Product();
        ProductDetailsUserControl control;
        public AddPriceForm(Product _product,ProductDetailsUserControl _control)
        {
            InitializeComponent();
            product = _product;
            this.Text = "สินค้า: "+product.Name +", ราคาปัจจุบัน: "+ product.CurrentPrice;
            this.startDateEdit.DateTime = DateTime.Now;
            control = _control;
        }

        private void addButton_Click(object sender, EventArgs e)
        {
            if (endDateEdit.EditValue != null)
            {
                repository.AddPrice(Convert.ToDecimal(amountTextEdit.Text), product.Id,
                   (DateTime)startDateEdit.EditValue, (DateTime)endDateEdit.EditValue, "", true);
                control.ReloadPrice();
                this.Close();
            }
            else
            {
                repository.AddPrice(Convert.ToDecimal(amountTextEdit.Text), product.Id,
                    (DateTime)startDateEdit.EditValue, null, "", true);
                control.ReloadPrice();
                this.Close();
            }
        }
    }
}